import request from "@/utils/request";

export interface SupplierQuery extends PageQuery {
  page?: number;
  limit?: number;
  keywords?: string;
  type?: string;
}

export interface SupplierDetail {
  id: number;
  title: number;
  type: string;
  status: number;
  sn?: string;
  secret?: string;
}

export interface SupplierForm {
  id?: number;
  type?: number;
  title?: string;
  name?: string;
  park_id?: number;
  service_money?: number;
  supplier_id?: number;
  deliver_type?: number;
  contact_name?: string;
  prepare_time?: string;
  deliver_time?: string;
  ava_price?: number;
  bag_price?: number;
  min_money?: number;
  contact_phone?: number;
  delivery_phone?: number;
  distrute_rank?: number;
  banner?: string; //店铺主图
  thumb?: string;//店铺头像
  store_time?: any;//营业时间
  base_shipping_price?: any;//基本费用
  picture_ids?: any;
  address?: string;
  shipping_fee?: any;
  qrcode_url?: string;
  description?: string;
  location?: string;
  food_license?: string;
  business_license?: string;
  order_end_time?: string;
  status?: number;
  is_label?: number;
  is_remark?: number;
  sort?: 20;
  is_open?: number;
  accept_order_type?: number;
  enable_profit_share?: number;
  stock_cal_type?: number;
  step?: number;
  role_id?: Array<number>;
}

const baseUri = "/mv1/api/supplier";

export function supplierList(query: SupplierQuery) {
  return request({
    url: baseUri + "/",
    method: "get",
    params: query,
  });
}

export function getSupplierOptions(data: any = null) {
  return request({
    url: baseUri + "/options",
    method: "get",
    params: data,
  });
}

export function getSupplierInit() {
  return request({
    url: baseUri + "/init",
    method: "get",
  });
}

export function supplierDetail(id: number) {
  return request({
    url: baseUri + "/detail/" + id,
    method: "get",
  });
}

export function createSupplier(data: SupplierForm) {
  return request({
    url: baseUri + "/edit",
    method: "post",
    data: data,
  });
}

export function updateSupplier(id: number, data: SupplierForm) {
  return request({
    url: baseUri + "/edit/" + id,
    method: "put",
    data: data,
  });
}

export function deleteSupplier(id: number) {
  return request({
    url: baseUri + "/" + id,
    method: "delete",
  });
}

/**
 * 获取店铺统计
 *
 * @param userId
 */
export function getSupplierStat() {
  return request({
    url: baseUri + "/stat",
    method: "post",
  });
}
